package com.report.bo;

import com.deepoove.poi.data.MergeCellRule;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Data
public class TableHeaderResultBo {
    /**
     * 表头数据行
     */
    private List<List<String>> rows = new ArrayList<>();
    /**
     * 表头行合并映射
     * key:行标
     * value:合并列下标区间
     */
    private Map<Integer, List<List<Integer>>> rowMergeMapping;
    /**
     * 表头列合并映射
     * key:列标
     * value:合并行下标区间
     */
    private Map<Integer, List<List<Integer>>> columnMergeMapping;

    /**
     * 获取合并规则
     *
     * @param ruleBuilder
     */
    public void processMergeRules(MergeCellRule.MergeCellRuleBuilder ruleBuilder) {

        if (rowMergeMapping != null) {
            for (Map.Entry<Integer, List<List<Integer>>> entry : rowMergeMapping.entrySet()) {
                List<List<Integer>> value = entry.getValue();
                for (List<Integer> integers : value) {
                    int start = integers.get(0);
                    int end = integers.get(1);
                    ruleBuilder.map(MergeCellRule.Grid.of(entry.getKey(), start), MergeCellRule.Grid.of(entry.getKey(), end));
                }
            }
        }
        if (columnMergeMapping != null) {
            for (Map.Entry<Integer, List<List<Integer>>> entry : columnMergeMapping.entrySet()) {
                List<List<Integer>> value = entry.getValue();
                for (List<Integer> integers : value) {
                    int start = integers.get(0);
                    int end = integers.get(1);
                    ruleBuilder.map(MergeCellRule.Grid.of(start, entry.getKey()), MergeCellRule.Grid.of(end, entry.getKey()));
                }
            }
        }
    }

}
